package com.function.controller;

import com.function.domin.dto.GetCurrentWeatherDTO;
import com.function.domin.pojo.Result;
import com.function.domin.vo.AddressVO;
import com.function.domin.vo.CurrentWeatherVO;
import com.function.service.BaiduMapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RestController
@Api(tags = "百度地图相关接口")
@RequestMapping("/baiduMap")
public class BaiduMapController {

    @Autowired
    private BaiduMapService baiduMapService;

    /**
     * 获取地址
     * @return
     */
    @ApiOperation("获取地址")
    @GetMapping("/getAddress")
    public Result<AddressVO> getAddress() throws IOException {
        AddressVO addressVO = baiduMapService.getAddress();
        log.info("查询地址：{}", addressVO);
        return Result.success(addressVO);
    }

    /**
     * 获取当前天气
     * @param getCurrentWeatherDTO
     * @return
     */
    @GetMapping("/getCurrentWeather")
    public Result<CurrentWeatherVO> getCurrentWeather(@RequestBody GetCurrentWeatherDTO getCurrentWeatherDTO) throws IOException {
        log.info("获取当前天气：{}", getCurrentWeatherDTO);
        CurrentWeatherVO currentWeatherVO = baiduMapService.getCurrentWeather(getCurrentWeatherDTO);
        return Result.success(currentWeatherVO);
    }

}
